package com.peng.community.util;

/**
 * 返回redis的key的工具类
 */
public class RedisKeyUtil {

    private static final String SPLIT = ":";
    private static final String ENTITY_LIKE = "like:entity";
    private static final String USER_LIKE = "like:user";
    private static final String PREFIX_FOLLOWEE_KEY = "followee";
    private static final String PREFIX_FOLLOWER_KEY = "follower";
    private static final String PREFIX_KAPTCHA = "kaptcha";
    private static final String PREFIX_TICKET = "ticket";
    private static final String PREFIX_USER = "user";
    private static final String PREFIX_UV = "uv";
    private static final String PREFIX_DAU = "dau";
    private static final String PREFIX_POST = "post";



    //喜欢某种实体的格式：like:entity:comment:12 //喜欢12号评论
    public static String getEntityLikeKey(int entityType, int entityId) {
        return ENTITY_LIKE + SPLIT + entityType + SPLIT + entityId;
    }

    //like:user:1
    public static String getUserLikeKey(int userId) {
        return USER_LIKE + SPLIT + userId;
    }


    //某个实体具有的粉丝
    //followee:entityType:entityId  value:zset(userId, now)
    public static String getFollowerKey(int entityType, int entityId) {
        return PREFIX_FOLLOWEE_KEY + SPLIT + entityType + SPLIT + entityId;
    }


    //某个用户关注的实体
    //follower:userId:entityType value:zset(entityId, now)
    public static String getFolloweeKey(int userId, int entityType) {
        return PREFIX_FOLLOWER_KEY + SPLIT + userId + SPLIT + entityType;
    }

    //获取验证码存储的key
    //验证码需求的时候，用户信息无法确定，但又确实需要一个唯一标识标记用户
    //下发一个临时的uuid作为用户的标识，让id通过cookie响应给用户，用户登录时根据这个key得到这个验证码
    public static String getKaptchaKey(String owner) {
        return PREFIX_KAPTCHA + SPLIT + owner;
    }

   //登录凭证的key
    public static String getTicketKey(String ticket) {
        return PREFIX_TICKET + SPLIT + ticket;
    }

    //登录凭证的key
    public static String getUserKey(int userId) {
        return PREFIX_USER + SPLIT + userId;
    }

    //获取单日UV key
    public static String getUVKey(String date) {
        return PREFIX_UV + SPLIT + date;
    }

    //获取区间UV key
    public static String getUVKey(String startDate, String endDate) {
        return PREFIX_UV + SPLIT + startDate + SPLIT + endDate;
    }

    //获取单日DAU key
    public static String getDAUKey(String date) {
        return PREFIX_DAU + SPLIT + date;
    }

    //获取区间UV key
    public static String getDAUKey(String startDate, String endDate) {
        return PREFIX_DAU + SPLIT + startDate + SPLIT + endDate;
    }

    //帖子热度分
    public static String getPostScoreKey() {
        return PREFIX_POST + SPLIT + "score";
    }
}
